#include "SurfaceClass.h"

int game(int argc, char* argv[]);
int main(int argc, char* argv[]) {
	int mainRtn = 0;
	mainRtn = game(argc, argv);
	return mainRtn;
}

int game(int argc, char* argv[]) {
	//Create a SDL screen.
	const int SCREEN_WIDTH = 640;
	const int SCREEN_HEIGHT = 480;
	ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT);

	//Create 2 SDL surface for the screen that just created.
	DisplaySurface backGround("D:\\MyGameProject\\pic\\1.bmp", screen);
	DisplaySurface frontImage("D:\\MyGameProject\\pic\\2.bmp", screen);

	//Blit backGround surface to screen and flip the screen.
	backGround.blit();
	screen.flip();

	//moving image's coordinate.
	int xpos = 0;
	int ypos = 0;
	//mouse's coordinate.
	int px = 0;
	int py = 0;
	//moving image's size.
	const int IMG_WIDTH = 128;
	const int IMG_HEIGHT = 128;
	//main loop.
	bool gameOver = false;
	while (gameOver == false) {
		//press ESC or click X to quit.
		SDL_Event gameEvent;
		while (SDL_PollEvent(&gameEvent) != 0) {
			if (gameEvent.type == SDL_QUIT) {
				gameOver = true;
			}
			if (gameEvent.type == SDL_KEYUP) {
				if (gameEvent.key.keysym.sym == SDLK_ESCAPE) {
					gameOver = true;
				}
			}
			//mouse event
			if (gameEvent.type == SDL_MOUSEMOTION) {
				px = gameEvent.motion.x;
				py = gameEvent.motion.y;
			}
		}

		if (xpos < px)
			xpos++;
		if (xpos > px)
			xpos--;
		if (ypos < py)
			ypos++;
		if (ypos > py)
			ypos--;

		backGround.blit(xpos, ypos, xpos, ypos, IMG_WIDTH, IMG_HEIGHT);
		frontImage.blit(xpos, ypos);
		screen.flip();
	}

	return 0;
}
